<?php
//****************************************************
// JTBC CMS Power by Jetiben.com
// Email: jetiben@hotmail.com
// Web: http://www.jtbc.net.cn/
//****************************************************
function jtbc_cms_module_list() {
	global $conn, $nlng, $ngenre;
	$tclassid = ii_get_num ( $_GET ['classid'] );
	$toffset = ii_get_num ( $_GET ['offset'] );
	global $nclstype, $nlisttopx, $npagesize;
	global $ndatabase, $nidfield, $nfpre;
	$tclassids = mm_get_sortids ( $ngenre, $nlng );
	$tmpstr = ii_itake ( 'module.list', 'tpl' );
	$tmpastr = ii_ctemplate ( $tmpstr, '{@recurrence_ida}' );
	$tmprstr = '';
	$tsqlstr = "select * from $ndatabase where " . ii_cfname ( 'hidden' ) . "=0";
	if ($tclassid != 0) {
		if (ii_cinstr ( $tclassids, $tclassid, ',' )) {
			mm_cntitle ( mm_get_sorttext ( $ngenre, $nlng, $tclassid ) );
			if ($nclstype == 0)
				$tsqlstr .= " and " . ii_cfname ( 'class' ) . "=$tclassid";
			else
				$tsqlstr .= " and " . ii_cfname ( 'cls' ) . " like '%|" . $tclassid . "|%'";
		}
	} else {
		if (! ii_isnull ( $tclassids ))
			$tsqlstr .= " and " . ii_cfname ( 'class' ) . " in ($tclassids)";
	}
	$tsqlstr .= " order by " . ii_cfname ( 'time' ) . " desc";
	$tcp = new cc_cutepage ();
	$tcp->id = $nidfield;
	$tcp->pagesize = $npagesize;
	$tcp->rslimit = $nlisttopx;
	$tcp->sqlstr = $tsqlstr;
	$tcp->offset = $toffset;
	$tcp->listkey = $tclassid;
	$tcp->init ();
	$trsary = $tcp->get_rs_array ();
	if (is_array ( $trsary )) {
		foreach ( $trsary as $trs ) {
			$tmptstr = $tmpastr;
			foreach ( $trs as $key => $val ) {
				$tkey = ii_get_lrstr ( $key, '_', 'rightr' );
				$GLOBALS ['RS_' . $tkey] = $val;
				$tmptstr = str_replace ( '{$' . $tkey . '}', ii_htmlencode ( $val ), $tmptstr );
			}
			$tmptstr = str_replace ( '{$id}', $trs [$nidfield], $tmptstr );
			$tmptstr = ii_creplace ( $tmptstr );
			$tmprstr .= $tmptstr;
		}
	}
	$tmpstr = str_replace ( JTBC_CINFO, $tmprstr, $tmpstr );
	$tmpstr = str_replace ( '{$cpagestr}', $tcp->get_pagestr (), $tmpstr );
	$tmpstr = str_replace ( '{$genre}', $ngenre, $tmpstr );
	$tmpstr = str_replace ( '{$classid}', $tclassid, $tmpstr );
	$tmpstr = ii_creplace ( $tmpstr );
	return $tmpstr;
}
function get_sorts() {
	global $db, $sort_database, $ngenre;
	
	$db->sqlcmd = "select * from $sort_database where sort_genre='$ngenre' order by sort_order";
	return $db->execute_reader ();
}
function jtbc_cms_module_detail() {
	global $db, $ndatabase, $nidfield;
	
	$id = ii_get_num ( $_GET ['id'] );
	
	$sorts = get_sorts ();
	
	$sql = "select * from $ndatabase where " . ii_cfname ( 'hidden' ) . "=0 and $nidfield=$id";
	$db->sqlcmd = $sql;
	$result = $db->get_first ();

	$sql = "select * from $ndatabase where " . ii_cfname ( 'hidden' ) . "=0 limit 3";
	$db->sqlcmd = $sql;
	$others = $db->execute_reader ();
	
	$sql = "select * from jtbc_shop_employees where  " . ii_cfname ( 'shopid' ) . "=$id limit 3";
	$db->sqlcmd = $sql;
	$employees = $db->execute_reader ();
	
    $sql = "select * from specialoffer where a_shopid=$id limit 5";
	$db->sqlcmd = $sql;
	$specialofferarr = $db->execute_reader ();
	include View ( "detail" );
}

function jtbc_cms_module_index() {
	global $conn, $nlng, $ngenre;
	global $sort_database, $sort_idfield;
	$tclassid = ii_get_num ( $_GET ['classid'] );
	$toffset = ii_get_num ( $_GET ['offset'] );
	global $nclstype, $nlisttopx, $npagesize;
	global $ndatabase, $nidfield, $nfpre;
	global $db;
	$db->sqlcmd = "select * from $sort_database where sort_genre='$ngenre'";
	$sorts = $db->execute_reader ();
	$result = array ();
	foreach ( $sorts as $sort ) {
		$sql = "select * from $ndatabase where " . ii_cfname ( 'class' ) . "='" . $sort ['sortid'] . "'  limit 3";
		$db->sqlcmd = $sql;
		$data = $db->execute_reader ();
		$result [] = array ("sort" => $sort, "data" => $data );
	}
  
	include View ( "index" );
}

function jtbc_cms_module() {
	switch ($_GET ['type']) {
		case 'list' :
			return jtbc_cms_module_list ();
			break;
		case 'detail' :
			return jtbc_cms_module_detail ();
			break;
		case 'index' :
			return jtbc_cms_module_index ();
			break;
		default :
			return jtbc_cms_module_index ();
			break;
	}
}
//****************************************************
// JTBC CMS Power by Jetiben.com
// Email: jetiben@hotmail.com
// Web: http://www.jtbc.net.cn/
//****************************************************
?>
